package io.github.leon406.view.edittext

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.appcompat.widget.AppCompatEditText

/** fix 嵌套滚动冲突 */
class NestedScrollEditText
@JvmOverloads
constructor(context: Context, attributes: AttributeSet? = null, defaultStyle: Int = 0) :
    AppCompatEditText(context, attributes, defaultStyle) {
    override fun onTouchEvent(event: MotionEvent): Boolean {
        when (event.actionMasked) {
            MotionEvent.ACTION_DOWN -> parent.requestDisallowInterceptTouchEvent(true)
            MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_UP ->
                parent.requestDisallowInterceptTouchEvent(false)
            else -> {
                // nop
            }
        }
        return super.onTouchEvent(event)
    }
}
